/**
 
 clibudget - a tool to manage your budgets from the command-line.

 Copyright 2022 - kzimmermann 

 This program is Free Software licensed under the terms and conditions of the
 GNU GPL v3. For more information, see https://www.gnu.org/licenses

*/

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "data.h"
#include "functions.h"

int
main(int argc, char* argv[])
{
    char* cat = "Transportation";
    char* query;
    asprintf(&query, "SELECT * FROM expenses WHERE category = '%s'", cat);
    printf("Example of hand-built query to be executed:\n\t%s\n", query);

    asprintf(&query, QUERY_INSERT, "Bills", "2022-06-28", 223, "Electric Bill");
    printf("The complex query is:\n\t%s\n", query);

    char* cfile;

#ifdef DEBUG
    asprintf(&cfile, "./config");
#else
    asprintf(&cfile, "%s/%s/%s\n", getenv("HOME"), CONFIG_DIR, CONFIG_FILE);
#endif

    int status = make_config(cfile);
    if (status == 1) {
        printf("Errors encountered. Exiting...\n");
        return 1;
    }
    else {
#ifdef DEBUG
        printf("Configuration file created at: %s/%s\n", getenv("PWD"), cfile);
#else
        printf("Configuration file created at: %s\n", cfile);
#endif
    }

    status = read_config(cfile);

    if (status == 1) {
        printf("Errors encountered. Exiting...\n");
        return 1;
    }

    free(query);
    free(cfile);

    return 0;
}
